#include <iostream>
#include <vector>
#include <string>
#include <sstream>

#include "BinaryTree.hpp"
#include "Vector.hpp"

using namespace std;

class Solution
{
public:
	vector<vector<int>> levelOrder(TreeNode *root)
	{
		vector<vector<int>> ret;
		if (root == nullptr)
		{
			return ret;
		}
		vector<TreeNode *> nodes;
		vector<TreeNode *> nextNodes;
		nodes.push_back(root);
		while (!nodes.empty())
		{
			vector<int> temp;
			for (auto node : nodes)
			{
				temp.push_back(node->val);
				if (node->left != nullptr)
					nextNodes.push_back(node->left);
				if (node->right != nullptr)
					nextNodes.push_back(node->right);
			}
			ret.push_back(temp);
			nodes = nextNodes;
			nextNodes.clear();
		}
		return ret;
	}
};

int main()
{
	cout << "code102" << endl;
	TreeNode *root = CreatTree("[3,9,20,null,null,15,7]", "null");
	Solution s;
	vector<vector<int>> ord = s.levelOrder(root);
	Print2DVector(ord);
	return 0;
}